<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'admincompany.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link rel="stylesheet" type="text/css" href="lib/layui/css/layui.css"/>
	<script src="lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
  </head>
  <script type="text/html" id="toolbarPro">
  
</script>
<script type="text/html" id="barProduct">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
 
</script>
  <script>
  //公司信息
 layui.use(["table","jquery","layer","form",], function() {
			var table = layui.table;
			var form=layui.form;
			var layer=layui.layer;
			var $=layui.jquery;
			
			
		table.on('tool(companytable)', function(obj) {
		  	var data = obj.data;
		  	//console.log(obj)
		  	if(obj.event === 'del') {
		  		layer.confirm('真的删除行么', function(index) {
		 			/* $.post('http://stuapi.ysdjypt.com/api/DeleteUser',{
		 				uId:data.Id,
						token:"88d6a749-5265-4439-964d-52d993c7ef7f"
		 			},function(res){
		 				if(res.success){
		 					layer.alert("删除成功");
		 					table.reload("userReload");
		 				}else{
		 					layer.alert("删除失败");
		 				}
		 			},"json"); */
		  		});
		  	}else if(obj.event === 'edit') {
		  		 layer.open({
					type: 1, 
					content:$("#updateproform"),
					area: ['800px', '600px']
					 ,offset: ['100px']
					});
					 //给表单赋值
						form.val("updateproform", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
						  "cmark":data.cmark // "name": "value"
						 ,"cphone":data.cphone
						 ,"ctel":data.ctel
						 ,"cemail":data.cemail
						 ,"caddress":data.caddress
						 ,"curl":data.curl
						
						 
						});
					
					//表单监听提交	
				form.on('submit(updateproduct)', function(data){
					//表单序列化，快速获取表单中所有name属性
					var str=$("#updateproform").serialize()+"&order=2";
				  $.post('AdmincompanyServlet',str,function(res){
				  	if(res.result.success){
				  		layer.closeAll();//关闭所有弹窗
				  		layer.msg(res.result.success);
				  		table.reload("productReload");//表格刷新
				  		$("#updateproform")[0].reset();//清空表单
				  		form.render();
				  	}else{
				  		layer.msg(res.result.success);
				  	}
				  },"json");
				  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
				 });
				
		  	}
  		});	
			  
			
  //方法级渲染
  table.render({
    elem: '#companytable'
    ,url: 'AdmincompanyServlet'
    ,toolbar: '#toolbarPro' //开启头部工具栏，并为其绑定左侧模板
    ,cols: [[
      {checkbox: true, fixed: true}
    // ,{field:'cid', width:80, title: '公司ID', sort: true}
      ,{field:'cmark', width:80, title: '网站名称',width: 150}
      ,{field:'cinformation', width:80, title: '公司介绍', width: 100}
      ,{field:'cphone', title: '热线电话'} 
      ,{field:'ctel', title: '联系方式', sort: true}
      ,{field:'cemail', title: '邮箱', sort: true}
      ,{field:'caddress', title: '公司地址'}
      ,{field:'curl', width:137, title: '公司网址', sort: true}
       ,{fixed: 'right', title:'操作', toolbar: '#barProduct',width: 100} 
      
    ]]
    ,id: 'productReload'
    ,page: true
    
    ,where:{//条件限制
    	order:1//通过order进行判断
    }
  });
  
   active = {
    reload: function(){
      var pname = $('#pname');
      var iswheel = $('#iswheel');
      
      //alert(pname.val());
      //执行重载
      table.reload('productReload', {
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
          
            pname: pname.val(),
            iswheel: iswheel.val(),
            order:1

        }
      }, 'data');
    }
  };
  
  $('#search').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});
</script>
    <body>
  		
 <!--  修改表单 -->
	  <form  class="layui-form" action="" lay-filter="updateproform" id="updateproform" style="display: none;">
				
		<input name="pid" style="display: none;" />
				
				<div class="layui-form-item">
				    <label class="layui-form-label">网站名称</label>
				    <div class="layui-input-inline">
				      <input lay-verify="rolename|required" type="text" name="cmark" autocomplete="off" placeholder="请输入网站名称" class="layui-input">
				    </div>
				    
			    </div>
			    <div class="layui-form-item"> 
			   		<label class="layui-form-label">热线电话</label>
				    <div class="layui-input-inline">
				      <input type="text" name="cphone" placeholder="请输入热线电话" autocomplete="off" class="layui-input">
				    </div>
				</div>
				<div class="layui-form-item"> 
			   		<label class="layui-form-label">联系方式</label>
				    <div class="layui-input-inline">
				      <input type="text" name="ctel" lay-verify="required|phone|number"  placeholder="请输入联系方式" autocomplete="off" class="layui-input">
				    </div>
				</div>
				<div class="layui-form-item"> 
			   		<label class="layui-form-label">邮箱</label>
				    <div class="layui-input-inline">
				      <input type="text" name="cemail" lay-verify="required|email"  placeholder="请输入邮箱" autocomplete="off" class="layui-input">
				    </div>
				</div>
				<div class="layui-form-item"> 
			   		<label class="layui-form-label">公司地址</label>
				    <div class="layui-input-inline">
				      <input type="text" name="caddress" placeholder="请输入公司地址" autocomplete="off" class="layui-input">
				    </div>
				</div>
				<div class="layui-form-item"> 
			   		<label class="layui-form-label">公司网址</label>
				    <div class="layui-input-inline">
				      <input type="text" name="curl" placeholder="请输入公司网址" autocomplete="off" class="layui-input">
				    </div>
				</div>
				
			     <div class="layui-form-item">
				    <div class="layui-input-block">
				      <button type="submit" class="layui-btn" lay-submit="" lay-filter="updateproduct">提交</button>
				      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
				    </div>
				</div>
			   </form>
  
 
  <table class="layui-hide" id="companytable" lay-filter="companytable"></table>
  </body>
</html>
